﻿using MySchool;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyKTV
{
    public partial class Form3 : Form
    {
        string targetPath;
        string address;
        int a;
        string da;
        string name;
        string name1;
        DBHelper db = new DBHelper();

        DataSet ds = new DataSet();

        public Form3()
        {
            InitializeComponent();
        }

        private void Form3_Load(object sender, EventArgs e)
        {
            db.OpenConnection();
            string sql = "select resource_path from resource_path where resource_id=1";
            SqlCommand comm = new SqlCommand(sql, db.Connection);
            SqlDataReader data = comm.ExecuteReader();

            while (data.Read())
            {

                targetPath = data["resource_path"].ToString();

            }
            data.Close();
            db.CloseConnection();
            db.OpenConnection();
            cbo_lei.DataSource = ds.Tables["singer_type"];
            cbo_lei.ValueMember = "singertype_id";
            cbo_lei.DisplayMember = "singertype_name";
        }

        private void 添加_Click(object sender, EventArgs e)
        {

            if (this.radioButton1.Checked)
            {
                a = 0;
            }
            else if (this.radioButton2.Checked)
            {
                a = 1;
            }
            else if (this.radioButton3.Checked)
            {
                a = 2;
            }
            db.OpenConnection();
            if (this.txt_Name.Text == "")
            {
                MessageBox.Show("姓名不能为空");
            }
            else if (this.cbo_lei.Text == "")
            {
                MessageBox.Show("请选择歌手类型");
            }
            

            else
            {
                if (radioButton1.Checked)
                {
                    da = "男";
                }
                else if (radioButton2.Checked)
                {
                    da = "女";
                }
                else if (radioButton3.Checked)
                {
                    da = "全部";
                }

                db.OpenConnection();
                if (this.cbo_lei.Text.ToString() == "大陆")
                {
                    address = "1";
                }
                else if (this.cbo_lei.Text.ToString() == "香港")
                {
                    address = "2";
                }
                else if (this.cbo_lei.Text.ToString() == "台湾")
                {
                    address = "3";
                }
                else if (this.cbo_lei.Text.ToString() == "欧美")
                {
                    address = "4";
                }
                else if (this.cbo_lei.Text.ToString() == "日韩")
                {
                    address = "5";
                }
                if (this.cbo_lei.Text.Trim().Equals(string.Empty))
                {
                    da = cbo_lei.Text;
                }

                string sql = " insert into singer_info(singer_name,singertype_id,singer_gender,singer_photo_url,singer_description)values(N'" + this.txt_Name.Text + "','" + address + "',N'" + da + "',N'" + name1+ "',N'" + this.txt_Miao.Text + "');";
                SqlCommand comm = new SqlCommand(sql, db.Connection);
                int count = comm.ExecuteNonQuery();
                if (count > 0)
                {
                    MessageBox.Show("添加成功");
                }
                else
                {
                    MessageBox.Show("添加失败");
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
        }

        private void cbo_lei_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void btn_liu_Click(object sender, EventArgs e)
        {
            //打开文件框
            OpenFileDialog openFileDialog = new OpenFileDialog();
            DialogResult result = openFileDialog.ShowDialog();
            if (result == DialogResult.OK)

            {


                name1 = openFileDialog.FileName.Substring(openFileDialog.FileName.LastIndexOf("\\") + 1);
                string name2 = openFileDialog.FileName.Substring(openFileDialog.FileName.LastIndexOf(".") + 1);
                if (name2 != "jpg")
                {
                    MessageBox.Show("文件类型错误！");
                    return;
                }

                this.pictureBox1.Image = Image.FromFile(openFileDialog.FileName);

                File.Copy(openFileDialog.FileName, targetPath + "\\" + name1);


            }
        }

        private void ucSplitLabel1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            Close();
        }
    }
}
    

    

